<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑运动员</title>
    <script src="../../res/js/base.js"></script>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <script src="../../js/login_common.js"></script>
    <style type="text/css">
        #bscjDiv{
            text-align: center;
            display: none;
        }

        #tableDiv{

            margin:auto;
            width: 805px;
        }
    </style>
</head>
<body>

<script type="text/javascript">
    //全局同步
    $.ajaxSetup({
        async: false
    });

</script>
<script>
    var table2 = null;
    var form = null;
    var table = null;
    layui.use(['form', 'layedit', 'laydate','table'], function() {
        var  layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        form = layui.form;
        table = layui.table;


        //日期
        laydate.render({
            elem: '#birthday'
        });
        laydate.render({
            elem: '#joinTime'
        });

        $("#creater").val(window.loginObj.user.userName);


        //加载下拉框
        loadType();

        if(window.loginObj.user.companyNum=="2"){
            $("#coachDiv").css("display","none");
            $("#coachId").val(window.loginObj.user.filId);
        }


        $("#closeSave").on("click",function () {
            //关闭当前层
            //当你在iframe页面关闭自身时
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

        //点保存按钮
        $("#saveButton").on("click",function (obj) {

            var athleteName = $("#athleteName").val();
            if(athleteName.length==0|| athleteName==null){
                layer.msg("请输入运动员名称");
                return;
            }

            var coachId = $("#coachId").val();
            if(coachId.length==0|| coachId==null){
                layer.msg("请选择教练员");
                return;
            }

            //获取教练员名称
            $("#coachName").val($('#coachId option:selected').text());

            var fromData = getFormData("fromone");//获取表单数据

            var url = "http://127.0.0.1:8900/emp/athlete";

            $.ajax({
                url: url,//地址
                dataType: 'json',//数据类型
                type: 'POST',//类型
                timeout: 2000,//超时
                data:fromData,//数据
                //请求成功
                success: function (obj, status) {
                    if(obj.num==1){

                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 500 //0.5秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.newLoad();
                        });

                    }else{
                        layer.msg(obj.msg);
                    }
                },
                //失败/超时
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus === 'timeout') {
                        layer.msg("请求超时");
                        setTimeout(function () {
                            layer.msg('重新请求');
                        }, 2000);
                    }
                }
            });
        });

    });

    //加载下拉框
    function loadType(){
        //判断是不是查看

        var select = getQueryString("select");
        if(select==1) {

            $("#buttonDiv").css("display", "none");
            $("#bscjDiv").css("display", "block");

            $(":text").prop("placeholder","");
            $("textarea").prop("placeholder","");

            var formq = document.forms[0];
            for (var i = 0; i < formq.length; i++) {
                var element = formq.elements[i];
                //部分元素可以编号     element.name  是元素自定义 name
                if (element.name != "auditEntity.auditContent"
                    && element.name != "auditEntity.auditAutograph"
                    && element.name != "auditEntity.auditTime"
                    && element.name != "auditEntity.auditState"
                    && element.name != "submitBtn"
                    && element.name != "reset"
                    && element.name != "id"
                    && element.name != "processInstanceId"
                    && element.name != "updateForm") {
                    element.disabled = "true";
                }
            }
        }

        var url = getRootPath() + "atsDataDicController/findAll";
        var data = {"dcode":"1"};
        $.post(url,data,function (obj) {
            $.each(obj,function (i,item) {
                $("#level").append("<option value='"+item.did+"'>"+item.dname+"</option>");
            });
        },"json");


        var url = getRootPath() + "atsDataDicController/findAll";
        var data = {"dcode":"2"};
        $.post(url,data,function (obj) {
            $.each(obj,function (i,item) {
                $("#education").append("<option value='"+item.did+"'>"+item.dname+"</option>");
            });
        },"json");


        var url = getRootPath() + "atsDataDicController/findAll";
        var data = {"dcode":"3"};
        $.post(url,data,function (obj) {
            $.each(obj,function (i,item) {
                $("#bestResult").append("<option value='"+item.did+"'>"+item.dname+"</option>");
            });
        },"json");


        $.ajax({
            url: "http://127.0.0.1:8900/emp/getcoachs",//地址
            dataType: 'json',//数据类型
            type: 'POST',//类型
            timeout: 2000,//超时
            //请求成功
            success: function (obj, status) {
                $.each(obj,function (i,item) {
                    $("#coachId").append("<option value='"+item.coachId+"'>"+item.coachName+"</option>");
                });
            },
            //失败/超时
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus === 'timeout') {
                    layer.msg("请求超时");
                    setTimeout(function () {
                        layer.msg('重新请求');
                    }, 2000);
                }
            }
        });


        // var url = getRootPath() + "AtsEmpCoachController/findAll";
        // var data = null;
        // $.post(url,data,function (obj) {
        //     $.each(obj,function (i,item) {
        //         $("#coachId").append("<option value='"+item.coachId+"'>"+item.coachName+"</option>");
        //     });
        // },"json");

        var id = getQueryString("id");
        if (id !="" && id!=null) {
            findByid(id);
        }

        var url = getRootPath() + "AtsEmpAthleteResultsController/selectAll";

        if (id !="" && id!=null) {
            url+='?athleteId='+id;
        }

        //第一个实例
        table2 = table.render({
            elem : '#demo',
            url : url //数据接口
            ,
            cols : [ [ //表头
                {
                    field : 'matchName',
                    title : '比赛名称',
                    width : 200
                }, {
                    field : 'matchItem',
                    title : '比赛项目',
                    width : 200
                },{
                    field : 'matchResult',
                    title : '比赛成绩',
                    width : 200
                },{
                    field : 'matchTime',
                    title : '比赛时间',
                    width : 200
                }  ] ]
        });

        form.render();
    }


    function findByid(id) {
        var url = "http://127.0.0.1:8900/emp/athlete/"+id;

        $.ajax({
            url: url,//地址
            dataType: 'json',//数据类型
            type: 'GET',//类型
            timeout: 2000,//超时
            //请求成功
            success: function (obj, status) {
                $("#athleteId").val(obj.athleteId);
                $("#athleteName").val(obj.athleteName);
                $("#deptName").val(obj.deptName);
                $("#postName").val(obj.postName);

                $("input[name='athleteSex'][value='"+obj.athleteSex+"']").attr("checked",true);

                $("input[name='hand'][value='"+obj.hand+"']").attr("checked",true);

                $("#organName").val(obj.organName);
                $("#nativePlace").val(obj.nativePlace);
                $("#birthday").val(obj.birthday);
                $("#play").val(obj.play);
                $("#club").val(obj.club);
                $("#trainingYears").val(obj.trainingYears);
                $("#joinTime").val(obj.joinTime);
                $("#level").val(obj.level);
                $("#oldCoach").val(obj.oldCoach);
                $("#coachId").val(obj.coachId);
                $("#coachName").val(obj.coachName);
                $("#graduateSchool").val(obj.graduateSchool);
                $("#education").val(obj.education);
                $("#family").val(obj.family);
                $("#bestResult").val(obj.bestResult);
                $("#athleteExp").val(obj.athleteExp);
                $("#phone").val(obj.phone);
                $("#addr").val(obj.addr);
                $("#other").val(obj.other);
                $("#technical").val(obj.technical);
                $("#tactics").val(obj.tactics);
                $("#mentality").val(obj.mentality);

                form.render();
            },
            //失败/超时
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus === 'timeout') {
                    layer.msg("请求超时");
                    setTimeout(function () {
                        layer.msg('重新请求');
                    }, 2000);
                }
            }
        });
    }
</script>

<form class="layui-form" action="" id="fromone">

    <input id="athleteId" name="athleteId" type="hidden">
    <input id="creater" name="creater" type="hidden">

        <div class="layui-inline">
            <label class="layui-form-label">运动员姓名</label>
            <div class="layui-input-block">
                <input type="text" name="athleteName" id="athleteName" lay-verify="title" autocomplete="off" placeholder="请输入运动员姓名" class="layui-input" maxlength="128">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">部门名称</label>
            <div class="layui-input-block">
                <input type="text" name="deptName" id="deptName" lay-verify="title" placeholder="请输入部门名称" autocomplete="off" class="layui-input" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">岗位名称</label>
            <div class="layui-input-block">
                <input type="text" name="postName" id="postName" lay-verify="title" autocomplete="off" placeholder="请输入岗位名称" class="layui-input" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">注册单位</label>
            <div class="layui-input-block">
                <input type="text" name="organName" id="organName" lay-verify="title" autocomplete="off" placeholder="请输入注册单位" class="layui-input" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="phone" id="phone" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入联系方式" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">毕业院校</label>
            <div class="layui-input-block">
                <input type="text" name="graduateSchool" id="graduateSchool" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入毕业院校" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">打法</label>
            <div class="layui-input-block">
                <input type="text" name="play" id="play" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入打法" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">俱乐部</label>
            <div class="layui-input-block">
                <input type="text" name="club" id="club" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入俱乐部" maxlength="128">
            </div>
        </div>

    <div class="layui-inline">
        <label class="layui-form-label">进队时间</label>
        <div class="layui-input-inline">
            <input type="text" name="joinTime" id="joinTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">出生年月</label>
        <div class="layui-input-inline">
            <input type="text" name="birthday" id="birthday" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">训练年限</label>
        <div class="layui-input-inline">
            <input type="text" name="trainingYears" id="trainingYears" lay-verify="title" autocomplete="off" placeholder="请输入训练年限" class="layui-input" maxlength="128">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">籍贯</label>
        <div class="layui-input-inline">
            <input type="text" name="nativePlace" id="nativePlace" lay-verify="title" placeholder="请输入籍贯" autocomplete="off" class="layui-input" maxlength="128">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">习惯手</label>
            <div class="layui-input-inline">
                <input type="radio" name="hand" value="左手" title="左手" checked="">
                <input type="radio" name="hand" value="右手" title="右手">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <input type="radio" name="athleteSex" value="男" title="男" checked="">
                <input type="radio" name="athleteSex" value="女" title="女">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">技术等级</label>
            <div class="layui-input-inline">
                <select name="level" id="level" lay-filter="aihao">
                    <option value=""></option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">文化程度</label>
            <div class="layui-input-inline">
                <select name="education" id="education" lay-filter="aihao">
                    <option value=""></option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">最好成绩</label>
            <div class="layui-input-inline">
                <select name="bestResult" id="bestResult" lay-filter="aihao">
                    <option value=""></option>
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item">

        <div class="layui-inline" id="coachDiv">
            <label class="layui-form-label">现教练员</label>
            <div class="layui-input-inline">
                <select name="coachId" id="coachId" lay-filter="aihao">
                    <option value=""></option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">原教练员</label>
            <div class="layui-input-inline">
                <input type="text" name="oldCoach" id="oldCoach" lay-verify="title" autocomplete="off" placeholder="请输入原教练员" class="layui-input" maxlength="128">
            </div>
        </div>

        <input type="hidden" name="coachName" id="coachName" lay-verify="title" autocomplete="off" placeholder="请输入冗余教练员" class="layui-input" maxlength="128">

    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">家庭情况</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="family" id="family" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">运动员说明</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="athleteExp" id="athleteExp" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">通讯地址</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="addr" id="addr" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">其他说明</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="other" id="other" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">技术特征</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="technical" id="technical" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">战术特征</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="tactics" id="tactics" maxlength="128"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">心理特征</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="mentality" id="mentality" maxlength="128"></textarea>
        </div>
    </div>

    <div id="bscjDiv">
        <div id="tableDiv">
            <table id="demo" lay-filter="test"></table>
        </div>
    </div>

    <div class="layui-form-item" id="buttonDiv">
        <div class="layui-input-block">
            <input type="button" value="保存" class="layui-btn" id="saveButton">
            <input type="button" value="取消" class="layui-btn layui-btn-primary" id="closeSave">
        </div>
    </div>

</form>
</body>
</html>